package cn.shengchao.examstar.system.acl.adaptes.repostories;

import cn.shengchao.examstar.system.acl.ports.repostories.IXcxSettingsRepository;
import cn.shengchao.examstar.system.infrastructure.dao.TXcxSettingsDao;
import cn.shengchao.examstar.system.infrastructure.dao.po.TXcxSettings;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class TXcxSettingsRepository implements IXcxSettingsRepository {

    @Autowired
    private TXcxSettingsDao xcxSettingsDao;

    @Override
    public TXcxSettings getXcxSettings(String appid, String version) {
        TXcxSettings xcxSettings = xcxSettingsDao.selectOne(
                Wrappers.lambdaQuery(TXcxSettings.class)
                        .eq(TXcxSettings::getAppid, appid)
                        .eq(TXcxSettings::getVersion, version)
        );
        if (xcxSettings == null) {
            TXcxSettings tXcxSettings = new TXcxSettings();
            tXcxSettings.setAppid(appid);
            tXcxSettings.setVersion(version);
            tXcxSettings.setIsShow(true);
            return tXcxSettings;
        }
        return xcxSettings;
    }
}
